//
//  TestPayViewController.m
//  Commom
//
//  Created by 山刘 on 2019/1/17.
//  Copyright © 2019年 山刘. All rights reserved.
//
#import "CommomHeader.h"
#import "T1ViewController.h"

#import "SEGUrlparamsModel.h"
#import "SEGSystemnativeModel.h"

#import "YYKitMacro.h"
#import "NSString+YYAdd.h"

#import "TestPayViewController.h"

@interface TestPayViewControllerDataSource : NSObject
//存放外部数据源
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *targetClass;

-(instancetype)initName:(NSString*)name targetClass:(NSString*)targetClass;
@end

@implementation TestPayViewControllerDataSource
-(instancetype)initName:(NSString*)name targetClass:(NSString*)targetClass{
    if (self == [super init]) {
        _name = name;
        _targetClass = targetClass;
    }
    return self;
}
@end

@interface TestPayViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
// 数据源
@property (nonatomic, strong)NSArray<TestPayViewControllerDataSource*> *dataSource;
@end

@implementation TestPayViewController{
    NSString *defaultTableViewCellIdentifier;
}

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSUserDefaults standardUserDefaults] setObject:UserDefaultsClientServerValue_gama forKey:UserDefaultsClientServerKey];
    [[NSUserDefaults standardUserDefaults] setObject:UserDefaultsBrowerServerValue_gama forKey:UserDefaultsBrowerServerKey];
    [[NSUserDefaults standardUserDefaults] setObject:@"42" forKey:UserDefaultsClientVersionCodeTypeKey];
    
    [SEGHTTPBusinessManager seg_serRequestHeaderDictionary:@{
                                                               @"systemVersionCode":@"11.4.1",
                                                               @"phoneModel":@"iPhone6",
                                                               @"version":@"1.7.0",
                                                               @"SYSCODE":@"10",
                                                               @"communityId":@"67",
                                                               @"source":@"2",
                                                               @"platform":@"CMHK",
                                                               @"deviceId":@"FCACB98B-53CA-4314-AB10-56B6E7D2AA1B",
                                                               @"versionCode":@"41"
                                                               }];
    
//    [[SEGLoginV2Manager sharedManager]requestLoginWithPassword:@"222222" tel:@"18816820401" completed:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//        NSLog(@"%@",[SEGLoginV2Manager sharedManager].login.yy_modelToJSONString);
//        [[SEGProfileManager sharedManager]requestProfilecompleted:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//           NSLog(@"%@",[SEGProfileManager sharedManager].profile.yy_modelToJSONString);
//        }];
//    }];
    
    
    [self initViews];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
     [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
     [super viewDidDisappear:animated];
}

#pragma mark - private methods
// 初始化视图
-(void)initViews{
    defaultTableViewCellIdentifier = @"DefaultTableViewCellIdentifier";
    [self.view addSubview:self.tableView];
    
    NSMutableArray<TestPayViewControllerDataSource*> *tmp = [NSMutableArray array];
    [tmp addObject:[[TestPayViewControllerDataSource alloc]initName:@"账单、欠费" targetClass:@"testzhangdan"]];
    [tmp addObject:[[TestPayViewControllerDataSource alloc]initName:@"团购" targetClass:@"tuangou"]];
    self.dataSource = tmp;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    /*if (self.dataSource.count > section) {}*/
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:defaultTableViewCellIdentifier];
    if (!cell) cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defaultTableViewCellIdentifier];
    if (self.dataSource.count > indexPath.section) {
        cell.textLabel.text = self.dataSource[indexPath.section].name;
    }
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataSource.count;
}

#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44.0;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.dataSource.count > indexPath.section) {
        SEL sl = NSSelectorFromString(self.dataSource[indexPath.section].targetClass);
        if ([self respondsToSelector:sl]) {
            [self performSelector:sl];
        }
    }
}

#pragma mark - Getter
- (UITableView*)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:defaultTableViewCellIdentifier];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        //_tableView.backgroundColor = kColor_bg;
        //_tableView.separatorColor = kColor_L2;
        _tableView.tableFooterView = [[UIView alloc] init];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        if(@available(iOS 11.0, *)){
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _tableView.estimatedSectionHeaderHeight  = _tableView.estimatedSectionHeaderHeight > 0 ? _tableView.estimatedSectionHeaderHeight : 0;
            _tableView.estimatedSectionFooterHeight  = _tableView.estimatedSectionFooterHeight > 0 ? _tableView.estimatedSectionFooterHeight : 0;
        }
    }
    return _tableView;
}

-(NSArray<TestPayViewControllerDataSource *> *)dataSource{
    if (!_dataSource) {
        _dataSource = [[NSArray alloc] init];
    }
    return _dataSource;
}

#pragma mark - Setter
-(void)testzhangdan{
//    [[SEGPaymethodlistv2Manager sharedManager]requestIdForBillPaymentPayFinished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//        NSLog(@"%@",[SEGPaymethodlistv2Manager sharedManager].requestId);
//        
//        if (isSuccessed) {
//            [[SEGPaymethodlistv2Manager sharedManager] requestRestPaymethodlistv2WithRequestId:[SEGPaymethodlistv2Manager sharedManager].requestId finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//                 NSLog(@"%@",[SEGPaymethodlistv2Manager sharedManager].PayMethodListV2.yy_modelToJSONString);
//                
//                UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initSEGPaymentViewController:@{@"mentodInfos":[SEGPaymethodlistv2Manager sharedManager].PayMethodListV2.data.mentodInfos}];
//                [self.navigationController pushViewController:VC animated:YES];
//            }];
//        }
//    }];
}

-(void)tuangou{
    
//    [[SEGPaymethodlistv2Manager sharedManager]requestIdForRestWithSite:@"2" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//        if (isSuccessed) {
//            [[SEGPaymethodlistv2Manager sharedManager] requestRestPaymethodlistv2WithRequestId:[SEGPaymethodlistv2Manager sharedManager].requestId finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
//
//                NSDictionary *dat = [[SEGPaymethodlistv2Manager sharedManager].PayMethodListV2.data yy_modelToJSONObject];
//                UIViewController *VC = [[SEGUhomeMediator sharedInstance]seg_initSEGPaymentViewController:dat completed:^NSDictionary * _Nonnull(NSDictionary * _Nonnull method) {
//
//                    if (!( method && [method isKindOfClass:[NSDictionary class]] && [[method allKeys] containsObject:@"id"])) {
//                        return nil;
//                    }
//
////                    [[SEGPaytradeManager sharedManager]requestPaytradeForBillPaymentWithCustId:@"" payAmount:@"" disRuleIdStr:@"" billAmount:@"" acctItemIds:@"" houseId:@"" payMethod:[method valueForKey:@"id"] custType:@"" disAmount:@"" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
////
////                        complex =
////                    }];
//                }];
//
//                [self.navigationController pushViewController:VC animated:YES];
//            }];
//        }
//    }];
}
@end
